package org.recruit.system.controller;

import org.recruit.system.domain.Resume;
import org.recruit.system.service.IResumeService;
import org.recruit.system.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 个人用户简历Controller
 * 
 * @author teapot
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/system/resume")
public class ResumeController
{
    private String prefix = "system/resume";

    @Autowired
    private IResumeService resumeService;

    @GetMapping()
    public String resume()
    {
        return prefix + "/resume";
    }

    /**
     * 查询个人用户简历列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(Resume resume)
    {
        //startPage();
        List<Resume> list = resumeService.selectResumeList(resume);
        return AjaxResult.success(list);
    }

    /**
     * 新增个人用户简历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人用户简历
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Resume resume)
    {
        return AjaxResult.success(resumeService.insertResume(resume));
    }

    /**
     * 修改个人用户简历
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Resume resume = resumeService.selectResumeById(id);
        mmap.put("resume", resume);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人用户简历
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Resume resume)
    {
        return AjaxResult.success(resumeService.updateResume(resume));
    }

    /**
     * 删除个人用户简历
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(resumeService.deleteResumeByIds(ids));
    }
}
